﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <title>反馈类型</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="icon" href="favicon.ico">
    @Html.Style("~/scripts/layuiadmin/layui/css/layui.css")
    @Html.Style("~/scripts/layuiadmin/style/admin.css")
</head>
<body>
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="query-filter">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <div class="layui-input-inline" style="width:170px;">
                            <input type="text" class="layui-input" name="name" placeholder="设备名称" />
                        </div>
                    </div>
                    <div class="layui-inline" style="width:160px;">
                        <select name="typeId">
                            <option value="0">反馈类型</option>
                            @foreach (var item in ViewBag.Types)
                            {
                                <option value="@item.Id">@item.Name</option>
                            }
                        </select>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn" id="btnSearch">搜索</button>
                        <button class="layui-btn" id="btnExport">导出</button>
                        <button type="button" class="layui-btn layui-btn-danger" id="btnDelete">删除</button>
                        <a href="" id="aExport" target="_blank" style="display:none;">export</a>
                    </div>
                </div>
            </div>
            <div class="layui-card-body">
                <table id="feedbackList" lay-filter="feedbackList"></table>
            </div>
        </div>
    </div>
    <script type="text/html" id="feedbackListBar">
        {{# if(d.id > 0){}}
        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delete">删除</a>
        {{# }}}
    </script>
    @Html.Script("~/scripts/layuiadmin/layui/layui.js")
    <script type="text/javascript">
        layui.use(['form', 'layer', 'table'], function () {
            var layer = layui.layer,
                form = layui.form,
                table = layui.table,
                $ = layui.$,
                table = layui.table;
            initFeedbacks();
            $('#btnSearch').click(initFeedbacks);

            $('#btnExport').click(function () {
                var filterObj = form.val("query-filter");
                $('#aExport').attr('href', '/admin/feedback/export?deviceName=' + filterObj.name + '&typeId=' + filterObj.typeId);
                document.getElementById('aExport').click();
            });

            $('#btnDelete').click(function () {
                var checkStatus = table.checkStatus('feedbackListTable');

                if (checkStatus.data.length < 1) {
                    layer.msg('请选择数据');
                    return;
                }

                var ids = [];

                for (var i = 0; i < checkStatus.data.length; i++) {
                    ids.push(checkStatus.data[i].id);
                }

                $.post('/admin/feedback/delete-batch', { ids: ids }, function (res) {
                    if (res.code == 1) {
                        initFeedbacks();
                    } else {
                        layer.msg('操作失败')
                    }
                });
            });

            table.on('tool(feedbackList)', function (obj) {
                var layEvent = obj.event,
                    data = obj.data;

                layer.confirm('确定要删除？', {
                    title: '提示',
                    btn: ['确定', '取消'],
                    offset: '100px'
                }, function (index) {
                    $.post('/admin/feedback/delete', { id: data.id }, function (res) {
                        if (res.code == 1) {
                            table.reload('feedbackListTable');
                        } else {
                            layer.msg(res.msg);
                        }

                        layer.close(index);
                    });
                });
            });

            function initFeedbacks() {
                table.render({
                    elem: '#feedbackList',
                    url: '/admin/feedback/list',
                    cellMinWidth: 95,
                    method: 'post',
                    page: true,
                    where: form.val("query-filter"),
                    limit: 50,
                    limits: [20, 50, 100],
                    id: "feedbackListTable",
                    response: {
                        statusName: 'code' //规定数据状态的字段名称，默认：code
                        , statusCode: 1 //规定成功的状态码，默认：0
                        , msgName: 'msg' //规定状态信息的字段名称，默认：msg
                        , countName: 'count' //规定数据总数的字段名称，默认：count
                        , dataName: 'data' //规定数据列表的字段名称，默认：data
                    },
                    cols: [[
                        { type: "checkbox", fixed: "left", width: 50 },
                        { field: 'name', title: '设备名称', width: 200 },
                        { field: 'typeName', title: '反馈类型', width: 200 },
                        { field: 'remark', title: '备注' },
                        { field: 'addTime', title: '添加时间', width: 175 },
                        { title: '操作', templet: '#feedbackListBar', align: "center", width: 120 }
                    ]]
                });
            }
        });
    </script>
</body>
</html>